<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style type="text/css">
	body{overflow:auto;}
  thead tr {background-color: ActiveCaption; color: CaptionText;}
  th, td {vertical-align: top; font-family: "宋体", Arial, Helvetica, sans-serif; font-size: 9pt; padding: 3px; }
  table, td {border: 1px solid silver;}
  table {border-collapse: collapse;}
  thead .col0 {width: 20%;}
  thead .col1 {width: 75%;}
	td.col0{font-size:18px;font-weight:bold;color:#f00;}
</style>
<body class="white-bg">
    <table>
      <thead>
        <tr>
          <th class="col0">章节</th>
          <th class="col1">内容</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td class="col0">3.5 用户登录</td>
          <td class="col1"><span style="font-size:18px;"><span style="font-family: 宋体; text-indent: 28px;">大部分&nbsp;</span><span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 14px="">Web&nbsp;</span><span style="font-family: 宋体; text-indent: 28px;">系统都具有用户登录模块，因为只有登录用户才能拥有某些特定操作的权限。 要实现登录功能，必定有登录页面，当前项目的系统首页与登录页面集成在一个页面上，所以 修改了默认的&nbsp;</span><span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 14px="">index.html</span><span style="font-family: 宋体; text-indent: 28px;">。</span></span><br />  </td>
        </tr>
        <tr>
          <td class="col0">3.5.1 美化系统首页</td>
          <td class="col1"><div style="text-align: justify; text-indent: 28px;"><span style="font-family:宋体;"><span style="font-size: 18px;"></span></span><p><span style="font-family:宋体;">换一个漂亮的系统首页</span>index.html<span style="font-family:宋体;">，如果前端开发能力比较强，建议原创开发一个有个性特色的首页。为了节省时间，可以从其它网站获取免费开源的一些页面，例如从</span><span style="font-family:宋体;">模板之家</span><span style="font-family:宋体;">下载，然后可以进行一些修改和内容调整，例如：</span></p><p><span style="font-family:Wingdings;">l<span style="font-size:7pt;font-family:'Times New Roman';">&nbsp; </span></span><span style="font-family:宋体;">分离出需要的样式内容，新建</span>login.css<span style="font-family:宋体;">，存放于</span>WebRoot\include\css</p><p><span style="font-family:Wingdings;">l<span style="font-size:7pt;font-family:'Times New Roman';">&nbsp; </span></span><span style="font-family:宋体;">分离出需要的</span>javascript<span style="font-family:宋体;">内容，新建</span>login.js<span style="font-family:宋体;">，存放于</span>WebRoot\include\js</p><p><span style="font-family:Wingdings;">l<span style="font-size:7pt;font-family:'Times New Roman';">&nbsp; </span></span><span style="font-family:宋体;">整合其它需要的</span>js<span style="font-family:宋体;">和</span>css<span style="font-family:宋体;">等文件，放进项目中</span>include<span style="font-family:宋体;">的相应文件夹。</span></p><p><span style="font-family:Wingdings;">l<span style="font-size:7pt;font-family:'Times New Roman';">&nbsp; </span></span><span style="font-family:宋体;">在</span>index.html<span style="font-family:宋体;">文件中，引入需要的</span>js<span style="font-family:宋体;">和</span>css<span style="font-family:宋体;">等文件，当前页面使用了</span>EasyUI<span style="font-family:宋体;">框架，所以也引用了</span>easyui<span style="font-family:宋体;">的</span>js<span style="font-family:宋体;">和</span>css<span style="font-family:宋体;">等文件。</span></p><p><span style="font-size:14pt;font-family:Consolas;">&nbsp; </span><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">meta</span> <span style="color:#7F007F;">http-equiv</span>=<em><span style="color:#2A00FF;">&quot;Content-Type&quot;</span></em><span style="color:#7F007F;">content</span>=<em><span style="color:#2A00FF;">&quot;text/html; charset=utf-8&quot;</span></em> <span style="color:teal;">/&gt;</span></p><p>&nbsp;&nbsp;<span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">link</span> <span style="color:#7F007F;">rel</span>=<em><span style="color:#2A00FF;">&quot;stylesheet&quot;</span></em> <span style="color:#7F007F;">type</span>=<em><span style="color:#2A00FF;">&quot;text/css&quot;</span></em> <span style="color:#7F007F;">href</span>=<em><span style="color:#2A00FF;">&quot;./include/css/main.css&quot;</span></em><span style="color:teal;">/&gt;</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">link</span> <span style="color:#7F007F;">rel</span>=<em><span style="color:#2A00FF;">&quot;stylesheet&quot;</span></em> <span style="color:#7F007F;">type</span>=<em><span style="color:#2A00FF;">&quot;text/css&quot;</span></em> <span style="color:#7F007F;">href</span>=<em><span style="color:#2A00FF;">&quot;./include/easyui/themes/default/easyui.css&quot;</span></em><span style="color:teal;">/&gt;</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">link</span> <span style="color:#7F007F;">rel</span>=<em><span style="color:#2A00FF;">&quot;stylesheet&quot;</span></em> <span style="color:#7F007F;">type</span>=<em><span style="color:#2A00FF;">&quot;text/css&quot;</span></em> <span style="color:#7F007F;">href</span>=<em><span style="color:#2A00FF;">&quot;./include/easyui/themes/icon.css&quot;</span></em><span style="color:teal;">/&gt;</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">script</span> <span style="color:#7F007F;">type</span>=<em><span style="color:#2A00FF;">&quot;text/javascript&quot;</span></em> <span style="color:#7F007F;">src</span>=<em><span style="color:#2A00FF;">&quot;./include/js/jquery.min.js&quot;</span></em><span style="color:teal;">&gt;&lt;/</span><span style="color:#3F7F7F;">script</span><span style="color:teal;">&gt;</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">script</span> <span style="color:#7F007F;">type</span>=<em><span style="color:#2A00FF;">&quot;text/javascript&quot;</span></em> <span style="color:#7F007F;">src</span>=<em><span style="color:#2A00FF;">&quot;./include/easyui/jquery.easyui.min.js&quot;</span></em><span style="color:teal;">&gt;&lt;/</span><span style="color:#3F7F7F;">script</span><span style="color:teal;">&gt;</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">script</span> <span style="color:#7F007F;">type</span>=<em><span style="color:#2A00FF;">&quot;text/javascript&quot;</span></em> <span style="color:#7F007F;">src</span>=<em><span style="color:#2A00FF;">&quot;./include/easyui/locale/easyui-lang-zh_CN.js&quot;</span></em><span style="color:teal;">&gt;&lt;/</span><span style="color:#3F7F7F;">script</span><span style="color:teal;">&gt;</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">script</span> <span style="color:#7F007F;">type</span>=<em><span style="color:#2A00FF;">&quot;text/javascript&quot;</span></em> <span style="color:#7F007F;">src</span>=<em><span style="color:#2A00FF;">&quot;./include/js/login.js&quot;</span></em><span style="color:teal;">&gt;&lt;/</span><span style="color:#3F7F7F;">script</span><span style="color:teal;">&gt;</span></p><p><span style="font-family:Wingdings;">l<span style="font-size:7pt;font-family:'Times New Roman';">&nbsp; </span></span><span style="font-family:宋体;">删除不需要的代码，比如</span>action<span style="font-family:宋体;">，</span>method<span style="font-family:宋体;">，</span>type=&quot;submit&quot;…<span style="font-family:宋体;">。</span></p><p><span style="font-family:Wingdings;">l<span style="font-size:7pt;font-family:'Times New Roman';">&nbsp; </span></span><span style="font-family:宋体;">修改部分代码，例如修改用户名和密码</span>input<span style="font-family:宋体;">的</span>id<span style="font-family:宋体;">和</span>name<span style="font-family:宋体;">值，使其与</span>User<span style="font-family:宋体;">类中的属性一致，以便封装数据传输到后端。</span></p><p><span style="font-family:宋体;">首页核心</span>html<span style="font-family:宋体;">代码如下，主要实现用户在</span>web<span style="font-family:宋体;">系统的前端页面输入用户名和密码，然后点击“登录”按钮。软件开发技术的学习，主要是学会方法，要活学活用，切忌死记硬背、生搬硬套。所以不同的人实现的前端页面可以有不同的风格、特征。</span></p><p><span style="color:#444444;">&lt;form </span><span style="color:#397300;">id</span><span style="color:#444444;">=</span><span style="color:#880000;">&quot;login_form&quot;</span><span style="color:#444444;"> <strong>onsubmit=</strong></span><strong><span style="color:#880000;">&quot;returnfalse;&quot;</span></strong><span style="color:#444444;">&gt;</span></p><p><span style="color:#444444;">&lt;input type=</span><span style="color:#880000;">&quot;text&quot;</span><span style="color:#397300;">id</span><span style="color:#444444;">=</span><span style="color:#880000;">&quot;uid&quot;</span><span style="color:#444444;"> placeholder=</span><span style="color:#880000;">&quot;</span><span style="font-family:宋体;color:#880000;">用户名</span><span style="color:#880000;">...&quot;</span><span style="color:#444444;">&gt;</span></p><p><span style="color:#444444;">&lt;input type=</span><span style="color:#880000;">&quot;password&quot;</span><span style="color:#397300;">id</span><span style="color:#444444;">=</span><span style="color:#880000;">&quot;pwd&quot;</span><span style="color:#444444;"> placeholder=</span><span style="color:#880000;">&quot;</span><span style="font-family:宋体;color:#880000;">密码</span><span style="color:#880000;">...&quot;</span><span style="color:#444444;"> &gt;</span></p><p><span style="color:#444444;">&lt;/form&gt;</span></p><p><span style="color:#444444;">&lt;input </span><span style="color:#397300;">id</span><span style="color:#444444;">=</span><span style="color:#880000;">&quot;login_submit&quot;</span><span style="color:#444444;"> value=</span><span style="color:#880000;">&quot;</span><span style="font-family:宋体;color:#880000;">登录</span><span style="color:#880000;">&quot;</span><span style="color:#444444;"> &gt;</span></p><p><span style="font-family:Wingdings;">l<span style="font-size:7pt;font-family:'Times New Roman';">&nbsp; </span></span><span style="font-family:宋体;">将会在</span>login.js<span style="font-family:宋体;">中添加代码，实现表单信息的获取、检验、通过</span>ajax<span style="font-family:宋体;">向后端传输；处理后端返回的消息。以下</span>JS<span style="font-family:宋体;">代码，让首页上的热气球随机移动，呈现动态效果。如果看不懂，暂时不要去管它；这种效果你也可以不使用。</span></p><p>$(<strong><span style="color:#7F0055;">function</span></strong>(){</p><p>&nbsp;&nbsp;&nbsp;&nbsp; airBalloon(<span style="color:#2A00FF;">'div.air-balloon'</span>);</p><p>});</p><p><strong><span style="color:#7F0055;">function</span></strong> airBalloon(balloon){</p><p>&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>viewSize = [] , viewWidth = 0 , viewHeight = 0 ;</p><p>&nbsp;&nbsp;&nbsp;&nbsp; resize();&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; $(balloon).each(<strong><span style="color:#7F0055;">function</span></strong>(){</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(<strong><span style="color:#7F0055;">this</span></strong>).css({top:rand(40, viewHeight * 0.5 ) , left : rand( 10 , viewWidth - $(<strong><span style="color:#7F0055;">this</span></strong>).width() ) });</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fly(<strong><span style="color:#7F0055;">this</span></strong>);</p><p>&nbsp;&nbsp;&nbsp;&nbsp; });&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; $(window).resize(<strong><span style="color:#7F0055;">function</span></strong>(){</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resize()</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(balloon).each(<strong><span style="color:#7F0055;">function</span></strong>(){</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(<strong><span style="color:#7F0055;">this</span></strong>).stop().animate({top: rand(40, viewHeight * 0.5 ) , left :rand( 10 , viewWidth - $(<strong><span style="color:#7F0055;">this</span></strong>).width() ) } ,1000 , <strong><span style="color:#7F0055;">function</span></strong>(){</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fly(<strong><span style="color:#7F0055;">this</span></strong>);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</p><p>&nbsp;&nbsp;&nbsp;&nbsp; });</p><p>&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">function</span></strong>resize(){</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewSize = getViewSize();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewWidth = $(document).width() ;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewHeight = viewSize[1] ;</p><p>&nbsp;&nbsp;&nbsp;&nbsp; }</p><p>&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">function</span></strong>fly(obj){</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong> $obj= $(obj);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>currentTop = parseInt($obj.css(<span style="color:#2A00FF;">'top'</span>));</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>currentLeft = parseInt($obj.css(<span style="color:#2A00FF;">'left'</span>) );</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>targetLeft = rand( 10 , viewWidth - $obj.width() );</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>targetTop = rand(40, viewHeight /2 );</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>removing = Math.sqrt( Math.pow( targetLeft - currentLeft , 2 )&nbsp; + Math.pow( targetTop - currentTop , 2 ) );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>moveTime = removing / 24;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $obj.animate({ top : targetTop ,left : targetLeft} , moveTime * 1000 , <strong><span style="color:#7F0055;">function</span></strong>(){</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setTimeout(<strong><span style="color:#7F0055;">function</span></strong>(){</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fly(obj);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, rand(1000, 3000) );</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; }</p><p>&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">function</span></strong>rand(mi,ma){&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong> range= ma - mi;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong> out =mi + Math.round( Math.random() * range) ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">return</span></strong>parseInt(out);</p><p>&nbsp;&nbsp;&nbsp;&nbsp; }</p><p>&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">function</span></strong>getViewSize(){</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>de=document.documentElement;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>db=document.body;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>viewW=de.clientWidth==0 ?&nbsp; db.clientWidth: de.clientWidth;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">var</span></strong>viewH=de.clientHeight==0 ?&nbsp;db.clientHeight : de.clientHeight;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">return</span></strong>Array(viewW,viewH);</p><p>&nbsp;&nbsp;&nbsp;&nbsp; }</p><p>};</p><br /></div>  </td>
        </tr>
        <tr>
          <td class="col0">3.5.2 Ajax方法</td>
          <td class="col1"><p><span style="font-size:18px;">Ajax<span style="font-family:宋体;">是异步</span> JavaScript <span style="font-family:宋体;">和</span> XML<span style="font-family:宋体;">；是一种用于创建快速动态网页的技术；</span> Ajax<span style="font-family:宋体;">通过前端页面与后端服务器进行少量数据交换，使网页实现异步更新，可以在不重新加载整个网页的情况下，对网页的某部分进行更新。</span>Ajax<span style="font-family:宋体;">可使</span>Internet<span style="font-family:宋体;">应用程序更小、更快、更友好。</span></span></p><p><span style="font-size:18px;">$.ajax([settings]) <span style="font-family:宋体;">方法通过</span> HTTP <span style="font-family:宋体;">请求加载远程数据，是</span>jQuery <span style="font-family:宋体;">底层</span> AJAX <span style="font-family:宋体;">实现。常用参数配置</span>settings<span style="font-family:宋体;">：</span></span></p><p><span style="font-size:18px;"><span style="font-family:Wingdings;">l<span style="font-family: Times New Roman;">&nbsp; </span></span><strong><span style="color:#0479A7;">url </span></strong><span style="font-family:宋体;">发送请求的地址。</span></span></p><p><span style="font-size:18px;"><span style="font-family:Wingdings;">l<span style="font-family: Times New Roman;">&nbsp; </span></span><strong><span style="color:#0479A7;">type </span></strong><span style="font-family:宋体;">请求方式</span> (&quot;POST&quot; <span style="font-family:宋体;">或</span> &quot;GET&quot;)</span></p><p><span style="font-size:18px;"><span style="font-family:Wingdings;">l<span style="font-family: Times New Roman;">&nbsp; </span></span><strong><span style="color:#0479A7;">data </span></strong><span style="font-family:宋体;">发送到服务器的数据，必须为</span> Key/Value <span style="font-family:宋体;">格式。</span></span></p><p><span style="font-size:18px;"><span style="font-family:Wingdings;">l<span style="font-family: Times New Roman;">&nbsp; </span></span><strong><span style="color:#0479A7;">error </span></strong><span style="font-family:宋体;">请求失败后的回调函数。</span></span></p><p><span style="font-size:18px;"><span style="font-family:Wingdings;">l<span style="font-family: Times New Roman;">&nbsp; </span></span><strong><span style="color:#0479A7;">success </span></strong><span style="font-family:宋体;">请求成功后的回调函数。</span></span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">采用</span>jquery+ajax<span style="font-family:宋体;">，可以非常灵活地校验、封装和提交表单信息。</span></span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">在</span>login.js<span style="font-family:宋体;">文件中，添加一个</span>checkUserName<span style="font-family:宋体;">函数，用于校验和提交登录信息，代码如下。</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">Var base=</span><span style="color:#880000;">&quot;./&quot;;</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">$(<strong>function</strong>() {</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp; $(</span><span style="color:#880000;">'#login_form input'</span><span style="color:#444444;">).keydown(<strong>function</strong> (e) {</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>if</strong>(e.keyCode == </span><span style="color:#880000;">13</span><span style="color:#444444;">)</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; checkUserName();</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">});</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp; $(</span><span style="color:#880000;">&quot;#login_submit&quot;</span><span style="color:#444444;">).click(checkUserName);</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">});</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;</span></span></p><p><span style="font-size:18px;"><strong><span style="color:#444444;">function</span><span style="color:#880000;">checkUserName</span></strong><span style="color:#444444;">()//</span><span style="font-family:宋体;color:#444444;">登录前，校验用户信息</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">{&nbsp;&nbsp; </span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp; <strong>var</strong>a=$(</span><span style="color:#880000;">'#uid'</span><span style="color:#444444;">).val();</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp; <strong>var</strong>b=$(</span><span style="color:#880000;">'#pwd'</span><span style="color:#444444;">).val();</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp; <strong>if</strong>(a==</span><span style="color:#880000;">&quot;&quot;</span><span style="color:#444444;">){alert(</span><span style="color:#880000;">&quot;</span><span style="font-family:宋体;color:#880000;">请输入用户名</span><span style="color:#880000;">&quot;</span><span style="color:#444444;">);<strong>return</strong>;}</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp; <strong>if</strong>(b==</span><span style="color:#880000;">&quot;&quot;</span><span style="color:#444444;">){alert(</span><span style="color:#880000;">&quot;</span><span style="font-family:宋体;color:#880000;">请输入登录密码</span><span style="color:#880000;">&quot;</span><span style="color:#444444;">);<strong>return</strong>;}</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp; $.ajax({</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: base+</span><span style="color:#880000;">&quot;user/doLogin&quot;</span><span style="color:#444444;">,</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data:{</span><span style="color:#880000;">&quot;uid&quot;</span><span style="color:#444444;">:a,</span><span style="color:#880000;">&quot;pwd&quot;</span><span style="color:#444444;">:b},</span><span style="color:#888888;">//</span><span style="font-family:宋体;color:#888888;">只封装和传输指定的数据</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type:</span><span style="color:#880000;">&quot;POST&quot;</span><span style="color:#444444;">,</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; success: <strong>function</strong> (res) {</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>if</strong>(res.ok) {</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#397300;">window</span><span style="color:#444444;">.location.href=base+res.msg;</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<strong>else</strong>{alert(res.msg);}</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>return</strong></span><span style="color:#78A960;">false</span><span style="color:#444444;">;</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error: <strong>function</strong>(res) {alert(</span><span style="color:#880000;">&quot;</span><span style="font-family:宋体;color:#880000;">系统错误！</span><span style="color:#880000;">&quot;</span><span style="color:#444444;">);}</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp; });</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">}</span></span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">如果在登录窗口的输入框中，按下回车键或直接点击登录按钮，则执行函数</span>checkUserName<span style="font-family:宋体;">；在</span>checkUserName<span style="font-family:宋体;">函数中，首先获取用户输入的用户名和密码，然后校验，如果有一个没有输入，则弹出警告框，不再向后端发送登录请求；否则，</span><span style="font-family:宋体;">采用</span>JSON<span style="font-family:宋体;">形式只封装用户名和密码，向后端发送</span>post<span style="font-family:宋体;">登录请求；后端将处理结果返回，函数中继续判断返回的信息，如果有问题，则弹出提示框，否则跳转到后台管理页面。</span></span></p></td>
        </tr>
        <tr>
          <td class="col0">3.5.3 更友好的alert</td>
          <td class="col1"><p class="s6" style="margin: 0pt; padding: 0px 0px 0px 5pt; text-indent: 21pt; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="" line-height:="" 28px="">Js&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">中的&nbsp;</span>alert&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">中框用于显示一些给用户的提示信息，如图&nbsp;</span>3-20&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">所示，使用了语句：</span>alert(&quot;&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">请输入用户名</span>&quot;);<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">。</span></p><p style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt"><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 0pt; padding: 0px 0px 0px 97pt; font-family: times new roman serif; font-size: 9pt" line-height:="" 10pt="" text-align:="" center=""><span style="margin: 0px; padding: 0px;"><img th:src="@{/assets/javaeeimg/Image_035.png}" style="margin: 0px; padding: 0px;" alt="" /></span></p><p class="s9" style="margin: 0pt; padding: 4pt 0px 0px 5pt; font-family: 宋体; font-size: 9pt; text-align: center;">图&nbsp;<span class="p" style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt">3-20 alert&nbsp;</span>提示框</p><p class="s6" style="margin: 0pt; padding: 7pt 0px 0px 5pt; text-indent: 21pt; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="" line-height:="" 28px="">EasyUI&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">中的&nbsp;</span>alert&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">提示框显示一个提示窗口，比&nbsp;</span>Js&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">中的&nbsp;</span>alert&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">提示框更加漂亮，并且可以 定制输出，形式更灵活，如图&nbsp;</span>3-21&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">所示。</span></p><p style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt"><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 0pt; padding: 0px 0px 0px 139pt; font-family: times new roman serif; font-size: 9pt" line-height:="" 10pt="" text-align:="" center=""><span style="margin: 0px; padding: 0px;"><img th:src="@{/assets/javaeeimg/Image_036.png}" style="margin: 0px; padding: 0px;" alt="" /></span></p><p style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt"><br style="margin: 0px; padding: 0px;" /></p><p class="s6" style="margin: 0pt; padding: 0px 0px 0px 26pt; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">EasyUI alert&nbsp;<span class="s5" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 18px;">的应用方法：</span></p><p class="s9" style="margin: 0pt; padding: 5pt 0px 0px; font-family: 宋体; font-size: 9pt;">图&nbsp;<span class="p" style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt">3-21 EasyUI&nbsp;</span>中的&nbsp;<span class="p" style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt">alert&nbsp;</span>提示窗口</p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px;">（<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">1</span>）引用&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">EasyUI&nbsp;</span>库。在首页中链接&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">EasyUI&nbsp;</span>的样式文件和&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Js&nbsp;</span>库文件，通常把第三方官方 的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Js&nbsp;</span>和&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Css&nbsp;</span>库集中存放在&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">include&nbsp;</span>目录下面的专用文件夹，如把&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">EasyUI&nbsp;</span>库放在&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">include&nbsp;</span>目录下。 不同&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Js&nbsp;</span>或者不同&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Css&nbsp;</span>的引用顺序有先后关系，后引用的样式会代替前面引用的相同样式，但</p><p style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt"><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt"><br style="margin: 0px; padding: 0px;" /></p><p class="s5" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 18px; line-height: 28px;">先引用的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Js&nbsp;</span>变量或函数可以用在后引用的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Js&nbsp;</span>中。例如&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">jquery.min.js&nbsp;</span>的引用比较靠前，因为有 很多&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Js&nbsp;</span>会用到&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">jquery&nbsp;</span>技术。引用顺序参考如下：</p><p class="s5" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 18px; line-height: 28px;"></p><p><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">link</span> <span style="color:#7F007F;">rel</span>=<em><span style="color:#2A00FF;">&quot;stylesheet&quot;</span></em> <span style="color:#7F007F;">href</span>=<em><span style="color:#2A00FF;">&quot;./include/easyui/themes/default/easyui.css&quot;</span></em><span style="color:teal;">&gt;</span></p><p><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">link</span> <span style="color:#7F007F;">rel</span>=<em><span style="color:#2A00FF;">&quot;stylesheet&quot;</span></em> <span style="color:#7F007F;">href</span>=<em><span style="color:#2A00FF;">&quot;./include/easyui/themes/icon.css&quot;</span></em><span style="color:teal;">&gt;</span></p><p><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">script</span> <span style="color:#7F007F;">src</span>=<em><span style="color:#2A00FF;">&quot;./include/easyui/jquery.easyui.min.js&quot;</span></em><span style="color:teal;">&gt;&lt;/</span><span style="color:#3F7F7F;">script</span><span style="color:teal;">&gt;</span></p><p><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">script</span> <span style="color:#7F007F;">src</span>=<em><span style="color:#2A00FF;">&quot;./include/easyui/locale/easyui-lang-zh_CN.js&quot;</span></em><span style="color:teal;">&gt;&lt;/</span><span style="color:#3F7F7F;">script</span><span style="color:teal;">&gt;</span></p><p>1)<span style="font-size:7pt;font-family:'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family:宋体;">使用语法：</span></p><p><span style="color:red;">$.messager.alert(title, msg, icon, fn)</span></p><p style="margin: 0pt; padding: 2pt 0px 0px 47pt; font-family: times new roman serif; font-size: 9pt"><span class="ptimes new roman serif; font-size: 9pt" style="font-family: 宋体; font-size: 18px; margin: 0pt; padding: 0px;">&nbsp;</span><span style="font-family: 宋体; font-size: 18px; text-indent: 21pt;">参数说明：&nbsp;</span></p><p style="margin: 0pt; padding: 2pt 0px 0px 47pt; font-family: times new roman serif; font-size: 9pt"><span class="s6" times="" new="" roman="" serif="" font-size:="" 18px="" style="font-family: 宋体; font-size: 18px; margin: 0px; padding: 0px;">title</span><span style="font-family: 宋体; font-size: 18px; text-indent: 21pt;">：显示在头部面板上的标题文本。&nbsp;</span></p><p style="margin: 0pt; padding: 2pt 0px 0px 47pt; font-family: times new roman serif; font-size: 9pt"><span class="s6" times="" new="" roman="" serif="" font-size:="" 18px="" style="font-family: 宋体; font-size: 18px; margin: 0px; padding: 0px;">msg</span><span style="font-family: 宋体; font-size: 18px; text-indent: 21pt;">：要显示的消息文本。</span><br /></p><p class="s5" style="margin: 0pt; padding: 0px 0px 0px 26pt; font-family: 宋体;"><span class="s6" style="font-size: 18px; margin: 0px; padding: 0px;" times="" new="" roman="" serif="" font-size:="" 18px="">icon</span><span style="font-size: 18px;">：要显示的图标图片</span><span style="font-size: 18px; margin: 0px; padding: 0px;"><img th:src="@{/assets/javaeeimg/Image_037.png}" style="margin: 0px; padding: 0px;" alt="" /></span><span style="font-size: 18px;">。可用的值是：</span><span style="font-size:18px;"><strong><span style="font-family: Times New Roman, serif; color: red;">info</span></strong><span style="font-family: 宋体;">、</span><strong><span style="font-family: Times New Roman, serif; color: red;">question</span></strong><span style="font-family: 宋体;">、</span><strong><span style="font-family: Times New Roman, serif; color: red;">error</span></strong><span style="font-family: 宋体;">、</span><strong><span style="font-family: Times New Roman, serif; color: red;">warning</span></strong></span><span style="font-size: 18px;">。</span></p><p class="s6" style="margin: 0pt; padding: 1pt 0px 0px 26pt; font-family: " times="" new="" roman="" serif="" font-size:="" 18px=""><span style="font-size:18px;">fn</span><span class="s5" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 18px;">：当窗口关闭时触发的回调函数。</span></p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 26pt; font-family: 宋体; font-size: 18px;">（<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">3</span>）使用语句如下：</p><p style="margin: 0pt; padding: 0px 0px 0px 47pt; font-family: times new roman serif; font-size: 9pt"><span style="font-size:18px;"><span style="font-family: Times New Roman, serif; color: red;">$.messager.alert(&quot;</span><span style="font-family: 宋体; color: red;">系统提示</span><span style="font-family: Times New Roman, serif; color: red;">&quot;,&quot;</span><span style="font-family: 宋体; color: red;">请输入用户名</span><span style="font-family: Times New Roman, serif; color: red;">&quot;,&quot;warning&quot;);</span></span><br /></p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 26pt; font-family: 宋体; font-size: 18px;">在后面的开发中，均可以使用&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">EasyUI&nbsp;</span>的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">alert&nbsp;</span>提示窗口功能。</p>  </td>
        </tr>
        <tr>
          <td class="col0">3.5.4 标题图标</td>
          <td class="col1"><p class="s5" style="margin: 0pt; padding: 9pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px; text-align: justify;">打开某一个网页会在浏览器的标签栏处显示该网页的标题和图标，当网页被添加到收藏 夹或者书签中时也会出现网页的图标。添加标题图标会让&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Web&nbsp;</span>系统显得更专业。给网页标题 前添加一个小图标，效果如图&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">3-22&nbsp;</span>所示。</p><p style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt"><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 0pt; padding: 0px 0px 0px 168pt; font-family: times new roman serif; font-size: 9pt" line-height:="" 10pt="" text-align:="" center=""><span style="margin: 0px; padding: 0px;"><img th:src="@{/assets/javaeeimg/Image_038.png}" style="margin: 0px; padding: 0px;" alt="" /></span></p><p class="s9" style="margin: 0pt; padding: 4pt 0px 0px 5pt; font-family: 宋体; font-size: 9pt; text-align: center;">图&nbsp;<span class="p" style="margin: 0pt; padding: 0px; font-family: times new roman serif; font-size: 9pt">3-22&nbsp;</span>网页标题与图标</p><p class="s5" style="margin: 0pt; padding: 7pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px; text-align: justify;">实现方法是用&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">link&nbsp;</span>标签实现&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">shortcut icon</span>，图标文件可以在线制作&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">ICO</span>，也可用&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">PhotoShop&nbsp;</span>制作&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">256*256&nbsp;</span>的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">png&nbsp;</span>或&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">gif&nbsp;</span>文件，前景和背景对比度明显，前景内容较少但所占空间较多，这 样的图标显示效果会比较清晰。制作的图标文件可以存放到&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">include/img&nbsp;</span>目录下，通过标签&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">link&nbsp;</span>链接。</p><p style="margin: 0pt; padding: 3pt 0px 0px 47pt; font-family: times new roman serif; font-size: 9pt"><span style="font-size:18px;"><span style="font-family: Times New Roman, serif; color: teal;">&lt;</span><span style="font-family: Times New Roman, serif; color: rgb(63, 127, 127);">link</span><span style="font-family: Times New Roman, serif;"> <span style="color: rgb(127, 0, 127);">rel</span>=<em><span style="color:#2A00FF;">&quot;shortcuticon&quot;</span></em> <span style="color: rgb(127, 0, 127);">href</span>=<em><span style="color:#2A00FF;">&quot;./include/img/logo.png&quot;</span></em><span style="color: teal;">&gt;</span></span></span><br /><br /></p>  </td>
        </tr>
        <tr>
          <td class="col0">3.5.5 MVC概述</td>
          <td class="col1"><p class="s5" style="margin: 0pt; padding: 9pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px; text-align: justify;">前端页面，设计完成还需要后端服务器来响应和处理前端页面发送的请求。<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Nutz.Mvc&nbsp;</span>需 要与&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Web&nbsp;</span>服务器（比如&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Tomcat</span>）一起工作，它存在的意义就是要把一个标准的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">HTTP&nbsp;</span>请求， 转发到某一个&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Java&nbsp;</span>函数中，<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Nutz.Mvc&nbsp;</span>的工作方式图&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">3-23&nbsp;</span>所示。用户在浏览器打开&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Web&nbsp;</span>系统 前端页面（视图&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">V</span>），通过&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Form&nbsp;</span>或&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Ajax&nbsp;</span>发送&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">HTTP&nbsp;</span>请求，<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Web&nbsp;</span>系统通过&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">MVC&nbsp;</span>协调，由控制 器&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">C&nbsp;</span>中特定的方法（<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Java&nbsp;</span>函数）来响应用户请求，控制器&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">C&nbsp;</span>根据请求，调用模型中的业务逻 辑方法，业务逻辑调用&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Dao&nbsp;</span>中的方法访问数据库等持久化数据。模型处理访问的数据后，控 制器&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">C&nbsp;</span>将处理结果渲染&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">render</span>，返回&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Response&nbsp;</span>到前端页面，在前端页面显示或自动发起另一 个&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">HTTP&nbsp;</span>请求。</p><p style="margin: 0pt; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;"><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 0pt; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt; text-align: center;"><span style="margin: 0px; padding: 0px;"><img th:src="@{/assets/javaeeimg/Image_039.png}" style="margin: 0px; padding: 0px;" alt="" /></span></p><p style="margin: 0pt; padding: 3pt 0px 0px 296pt; text-indent: -13pt; font-family: Times New Roman, serif; font-size: 9pt; line-height: 17.88px;"><span style="font-family: 宋体; font-size: 9pt; text-align: center;">图&nbsp;</span><span class="p" style="font-size: 9pt; text-align: center; margin: 0pt; padding: 0px;">3-23 Nutz.Mvc&nbsp;</span><span style="font-family: 宋体; font-size: 9pt; text-align: center;">工作方式</span><br /></p><p class="s6" style="margin: 0pt; padding: 7pt 0px 0px 26pt; font-family: Times New Roman, serif; font-size: 18px;">MVC&nbsp;<span class="s5" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 18px;">是指模型（</span>model<span class="s5" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 18px;">）、视图（</span>view<span class="s5" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 18px;">）和控制器（</span>controller<span class="s5" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 18px;">），具体描述如下：</span></p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px; text-align: justify;">（<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">1</span>）<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Model</span>（模型）表示应用程序核心，是应用程序中用于处理数据逻辑的部分，负责 在数据库中存取数据。为了将数据访问与业务逻辑分离，提高业务精度，模型层又划分为&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">DAO&nbsp;</span>层和业务层（<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Service</span>）。</p><p class="s6" style="margin: 0pt; padding: 0px 0px 0px 47pt; text-indent: -21pt; font-family: Times New Roman, serif; font-size: 18px; line-height: 28px; text-align: justify;"><span class="s11" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Wingdings; font-size: 9pt;">?&nbsp;</span>DAO<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">（</span>Data Access Object<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">）—主要职能是将访问数据库的代码封装起来，让这些代 码不会在其他层出现或者暴露出来给其他层。</span></p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 47pt; text-indent: -21pt; font-family: 宋体; font-size: 18px; line-height: 15.12px; text-align: justify;"><span class="s11" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Wingdings; font-size: 9pt;">?&nbsp;</span>业务层—是整个系统最核心也是最具有价值的一层。该层封装应用程序的业务逻 辑，处理用户需求的数据。在业务处理过程中会访问原始数据或产生新数据，<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">DAO&nbsp;</span>层提供的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">DAO&nbsp;</span>类能很好地帮助业务层完成数据处理。</p><p class="s5" style="margin: 0pt; padding: 0px 0px 0px 26pt; font-family: 宋体; font-size: 18px;">（<span class="s6" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 18px;">2</span>）<span class="s6" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 18px;">View</span>（视图）显示数据，通常依据模型数据创建。</p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px; text-align: justify;">（<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">3</span>）<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Controller</span>（控制器）是应用程序中处理用户交互的部分。通常负责从视图&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">View&nbsp;</span>读 取用户请求，将其转发给模型&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Model</span>，经过处理后把结果返回到视图&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">View</span>。</p><p class="s6" style="margin: 0pt; padding: 0px 0px 0px 5pt; text-indent: 21pt; font-family: Times New Roman, serif; font-size: 18px; line-height: 15.26px; text-align: justify;">MVC&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">要实现的目标是将软件用户界面&nbsp;</span>View&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">和业务逻辑分离，降低代码之间的耦合， 以使代码可扩展性、可复用性、可维护性、灵活性加强。使同一个程序可以使用不同的表 现形式。控制器&nbsp;</span>Controller&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">将用户请求转发给模型层&nbsp;</span>Model<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">，经过处理后把结果返回到视图&nbsp;</span>View&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">层。</span></p> </td>
        </tr>
        <tr>
          <td class="col0">3.5.6 MVC注解</td>
          <td class="col1"><p class="s6" style="margin: 0pt; padding: 9pt 0px 0px 5pt; text-indent: 21pt; font-family: Times New Roman, serif; font-size: 18px; line-height: 28px; text-align: justify;">Nutz.Mvc&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">根据</span>@At&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">注解将一个&nbsp;</span>HTTP&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">请求路径同一个&nbsp;</span>Java&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">函数关联起来。子模块中任何 函数，只要是&nbsp;</span>public&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">且不是&nbsp;</span>static&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">的，都可以作为入口函数。标记入口函数的方法是在其上标</span><span style="font-family: 宋体; font-size: 18px;">注注解</span><span class="s6" style="font-size: 18px; margin: 0px; padding: 0px;">@At</span><span style="font-family: 宋体; font-size: 18px;">。使用不带参数的</span><span class="s6" style="font-size: 18px; margin: 0px; padding: 0px;">@At()</span><span style="font-family: 宋体; font-size: 18px;">注解，默认会使用小写的方法名</span><span class="s6" style="font-size: 18px; margin: 0px; padding: 0px;">/</span><span style="font-family: 宋体; font-size: 18px;">类名作为入口&nbsp;</span><span class="s6" style="font-size: 18px; margin: 0px; padding: 0px;">URL</span><span style="font-family: 宋体; font-size: 18px;">；有 参数时，以参数作为入口&nbsp;</span><span class="s6" style="font-size: 18px; margin: 0px; padding: 0px;">URL</span><span style="font-family: 宋体; font-size: 18px;">。</span></p><p class="s5" style="margin: 0pt; padding: 0px 0px 0px 26pt; font-family: 宋体; font-size: 18px;">任何一个请求，都会经过四道工序，才能获得返回结果。</p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 26pt; font-family: 宋体; font-size: 18px;">（<span class="s6" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 18px;">1</span>）过滤：通过&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 18px;">@Filters&nbsp;</span>注解可以为你的入口函数定义任意多的过滤器</p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px;">（<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">2</span>）适配：这个过程将&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">HTTP&nbsp;</span>输入流转换成入口函数的参数数组，默认输入流是传统的 名值对方式，例如文件上传&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">UploadAdptor</span>。</p><p class="s5" style="margin: 0pt; padding: 0px 0px 0px 26pt; font-family: 宋体; font-size: 18px;">（<span class="s6" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 18px;">3</span>）调用：调用入口函数，函数里面需要调用相关的业务层代码。</p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 26pt; font-family: 宋体; font-size: 18px;">（<span class="s6" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 18px;">4</span>）渲染：根据入口函数的返回，渲染&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 18px;">HTTP Response</span>。</p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px;">除了这种标准流程，<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Nutz.Mvc&nbsp;</span>还支持“动作链”的方式，可以让用户几乎无限地定制一 个请求的处理流程和方式。</p><p class="s5" style="margin: 0pt; padding: 1pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px; text-align: justify;">如果直接返回一个&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">View</span>，则用这个&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">View&nbsp;</span>来渲染，否则用函数的<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">@Ok&nbsp;</span>注解声明的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">View&nbsp;</span>来 渲染入口函数的返回对象。如果你的函数处理过程中抛出了异常，用<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">@Fail&nbsp;</span>注解声明的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">View&nbsp;</span>来渲染异常对象，返回值会保存在&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">request&nbsp;</span>的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">attr&nbsp;</span>中，名字是&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">obj</span>。</p><p class="s5" style="margin: 0pt; padding: 0px 0px 0px 26pt; font-family: 宋体; font-size: 18px;">表&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 18px;">3-8&nbsp;</span>是子模块上支持的注解，表&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 18px;">3-9&nbsp;</span>是子模块中入口函数上支持的注解。</p><p class="s14" style="margin: 0pt; padding: 9pt 0px 0px 5pt; font-family: 黑体, monospace; font-size: 9pt; text-align: center;">表&nbsp;<span class="s15" style="margin: 0px; padding: 0px; font-family: Arial, sans-serif; font-size: 9pt;">3-8&nbsp;</span>子模块上支持的注解</p><p style="margin: 0pt; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;"><br style="margin: 0px; padding: 0px;" /></p><div style='margin:0 auto;width: 900px;'><table cellspacing="0" style="margin: 0px 0px 0px 5.89399pt; padding: 0px; vertical-align: top; overflow: visible; font-family: &quot;Microsoft YaHei&quot;;font-size:16px; border-collapse: collapse;"><tbody style="margin: 0px; padding: 0px; vertical-align: top; overflow: visible;"><tr style="margin: 0px; padding: 0px; height: 18pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s16" style="margin: 0pt; padding: 1pt 0px 0px 21pt; font-family: 黑体, monospace; font-size: 9pt;">注 解</p></td><td style="margin: 0px; padding: 0px; width: 352pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s16" style="margin: 0pt; padding: 1pt 0px 0px; font-family: 黑体, monospace; font-size: 9pt; text-align: center;">说 明</p></td></tr><tr style="margin: 0px; padding: 0px; height: 41pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p style="margin: 0pt; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;"><br style="margin: 0px; padding: 0px;" /></p><p class="s17" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@IocBean</p></td><td style="margin: 0px; padding: 0px; width: 352pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 1pt 5pt 0px; font-family: Times New Roman, serif; font-size: 9pt;">AnnotationIocLoader<span class="s18" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 9pt;">（注解加载器）根据它来判断哪些类应该被自己加载&nbsp;</span>AnnotationIocLoader&nbsp;<span class="s18" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 9pt;">根据</span>@Inject&nbsp;<span class="s18" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 9pt;">来注入类的属性（例如&nbsp;</span>Dao&nbsp;<span class="s18" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 9pt;">对象），有</span>@IocBean&nbsp;<span class="s18" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 9pt;">它才 会生效</span></p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@At</p></td><td style="margin: 0px; padding: 0px; width: 352pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">模块所有入口函数的&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">URL&nbsp;</span>前缀</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@Ok</p></td><td style="margin: 0px; padding: 0px; width: 352pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">模块默认成功视图</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@Fail</p></td><td style="margin: 0px; padding: 0px; width: 352pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">模块默认失败视图</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@AdaptBy</p></td><td style="margin: 0px; padding: 0px; width: 352pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">模块默认&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">HTTP&nbsp;</span>参数适配方式</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@Filters</p></td><td style="margin: 0px; padding: 0px; width: 352pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">模块默认的过滤器数组</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@Encoding</p></td><td style="margin: 0px; padding: 0px; width: 352pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">模块默认&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">HTTP&nbsp;</span>请求的输入输出字符编码</p></td></tr></tbody></table></div><p style="margin: 0pt; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;"><br style="margin: 0px; padding: 0px;" /></p><p class="s14" style="margin: 0pt; padding: 2pt 0px 0px 47pt; font-family: 黑体, monospace; font-size: 9pt; text-align: center;">表&nbsp;<span class="s15" style="margin: 0px; padding: 0px; font-family: Arial, sans-serif; font-size: 9pt;">3-9&nbsp;</span>入口函数上支持的注解</p><p style="margin: 0pt; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;"><br style="margin: 0px; padding: 0px;" /></p><div style='margin:0 auto;width: 900px;'><table cellspacing="0" style="margin: 0px 0px 0px 5.29399pt; padding: 0px; vertical-align: top; overflow: visible; font-family: &quot;Microsoft YaHei&quot;;font-size:16px; border-collapse: collapse;"><tbody style="margin: 0px; padding: 0px; vertical-align: top; overflow: visible;"><tr style="margin: 0px; padding: 0px; height: 19pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s16" style="margin: 0pt; padding: 1pt 0px 0px 21pt; font-family: 黑体, monospace; font-size: 9pt;">注 解</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s16" style="margin: 0pt; padding: 1pt 0px 0px; font-family: 黑体, monospace; font-size: 9pt; text-align: center;">说 明</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@At</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">函数对应的&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">URL</span></p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@Ok</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">成功视图</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@Fail</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">失败视图</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@AdaptBy</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: Times New Roman, serif; font-size: 9pt;">HTTP&nbsp;<span class="s18" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 9pt;">参数适配方式</span></p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@Filters</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">函数的过滤器数组</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@Encoding</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: Times New Roman, serif; font-size: 9pt;">HTTP&nbsp;<span class="s18" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 9pt;">请求的输入输出字符编码</span></p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@GET</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">限定函数接受&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">HTTP GET&nbsp;</span>请求</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@POST</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">限定函数接受&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">HTTP POST&nbsp;</span>请求</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@PUT</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">限定函数接受&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">HTTP PUT&nbsp;</span>请求</p></td></tr><tr style="margin: 0px; padding: 0px; height: 18pt;"><td style="margin: 0px; padding: 0px; width: 70pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 6pt; font-family: Times New Roman, serif; font-size: 9pt;">@DELETE</p></td><td style="margin: 0px; padding: 0px; width: 353pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 宋体; font-size: 9pt;">限定函数接受&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">HTTP DELETE&nbsp;</span>请求</p></td></tr></tbody></table></div> </td>
        </tr>
        <tr>
          <td class="col0">3.5.7 DAO接口方法</td>
          <td class="col1"><p class="s5" style="margin: 0pt; padding: 9pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px; text-align: justify;">目前流行的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Web&nbsp;</span>系统基本都需要数据库的支持，所以在系统的使用过程中，需要访问 数据库。软件开发人员需要编写公共&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">DAO&nbsp;</span>类，实现添加、删除、修改和查询数据库操作， 俗称增删改查（<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">CRUD</span>，即&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Create&nbsp;</span>添加数据、<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Read&nbsp;</span>读取查询数据、<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Update&nbsp;</span>修改数据和&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Delete&nbsp;</span>删除数据）。传统关系型数据库定义了四种数据操作：插入&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Insert</span>、删除&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Delete</span>、更新&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Update&nbsp;</span>和查询&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Query</span>，这四种操作涵盖了所有的数据操作。<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">Nutz.Dao&nbsp;</span>已经封装了表&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: Times New Roman, serif; font-size: 18px;">3-10&nbsp;</span>所示的数 据操作。</p><p style="margin: 0pt; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;"><br style="margin: 0px; padding: 0px;" /></p><p class="s14" style="margin: 0pt; padding: 0px 0px 0px 5pt; font-family: 黑体, monospace; font-size: 9pt; text-align: center;">表&nbsp;<span class="s15" style="margin: 0px; padding: 0px; font-family: Arial, sans-serif; font-size: 9pt;">3-10 Dao&nbsp;</span>的数据操作</p><p style="margin: 0pt; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;"><br style="margin: 0px; padding: 0px;" /></p><div style='margin:0 auto;width: 900px;'><table cellspacing="0" style="margin: 0px 0px 0px 5.294pt; padding: 0px; vertical-align: top; overflow: visible; font-family: &quot;Microsoft YaHei&quot;;font-size:16px; border-collapse: collapse;"><tbody style="margin: 0px; padding: 0px; vertical-align: top; overflow: visible;"><tr style="margin: 0px; padding: 0px; height: 18pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s16" style="margin: 0pt; padding: 1pt 0px 0px; font-family: 黑体, monospace; font-size: 9pt; text-align: center;">操作</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s16" style="margin: 0pt; padding: 1pt 0px 0px; font-family: 黑体, monospace; font-size: 9pt; text-align: center;">方法名</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s16" style="margin: 0pt; padding: 1pt 0px 0px; font-family: 黑体, monospace; font-size: 9pt; text-align: center;">说 明</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">插入</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">Insert</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">一条&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">SQL&nbsp;</span>插入一条记录或者多条记录</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">插入</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">FastInsert</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">一条&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">SQL</span>，通过&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">batch&nbsp;</span>插入多条记录</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">删除</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">Delete</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">一条&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">SQL&nbsp;</span>删除一条记录</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">更新</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">Update</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">一条&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">SQL&nbsp;</span>更新一条或者多条记录</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">获取</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">Fetch</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">一条&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">SQL&nbsp;</span>获取一条记录</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">查询</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">Query</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">一条&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">SQL&nbsp;</span>根据条件获取多条记录</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">清除</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">Clear</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">一条&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">SQL&nbsp;</span>根据条件删除多条记录</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">建表</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">Create</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">根据实体建表</p></td></tr><tr style="margin: 0px; padding: 0px; height: 17pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">删表</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">Drop</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">根据实体<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">/</span>表名称进行删表</p></td></tr><tr style="margin: 0px; padding: 0px; height: 18pt;"><td style="margin: 0px; padding: 0px; width: 85pt; border-top-style: solid; border-top-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt; border-right-style: solid; border-right-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 6pt; font-family: 宋体; font-size: 9pt;">聚合</p></td><td style="margin: 0px; padding: 0px; width: 84pt; border-style: solid; border-width: 1pt;"><p class="s17" style="margin: 0pt; padding: 3pt 0px 0px 4pt; font-family: Times New Roman, serif; font-size: 9pt;">Func</p></td><td style="margin: 0px; padding: 0px; width: 254pt; border-top-style: solid; border-top-width: 1pt; border-left-style: solid; border-left-width: 1pt; border-bottom-style: solid; border-bottom-width: 1pt;"><p class="s18" style="margin: 0pt; padding: 0px 0px 0px 4pt; font-family: 宋体; font-size: 9pt;">执行&nbsp;<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">sum</span>、<span class="s17" style="margin: 0px; padding: 0px; font-family: Times New Roman, serif; font-size: 9pt;">count&nbsp;</span>等操作</p></td></tr></tbody></table></div> </td>
        </tr>
        <tr>
          <td class="col0">3.5.8 登录方法</td>
          <td class="col1"><p class="s5" style="margin: 0pt; padding: 9pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px; text-align: justify;">在已经了解&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Mvc&nbsp;</span>注解和&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Dao&nbsp;</span>接口方法后，下面介绍实现控制器中的登录方法。在&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">cn.lrw.newsnutz.module&nbsp;</span>包中创建子模块&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">UserAct&nbsp;</span>类，在&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">UserAct&nbsp;</span>类中实现对用户信息的增删改 查。例如，用户登录&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">doLogin</span>，实际上就是查找用户信息。在类中添加&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Ioc&nbsp;</span>相关注解或属性， 如<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">@IocBean</span>，<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">@Inject</span>，<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">@At&nbsp;</span>和&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">Dao&nbsp;</span>属性。注解<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">@Param&nbsp;</span>用于获取前端&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">request&nbsp;</span>的参数值。<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">doLogin&nbsp;</span>方法接收登录页面传来的&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">uid&nbsp;</span>和&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">pwd&nbsp;</span>信息，将其作为查询条件，在&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">user&nbsp;</span>表中查找是否有满足 条件的用户。根据查询结果，返回&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">json&nbsp;</span>格式的信息，返回信息使用&nbsp;<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">NutMap&nbsp;</span>封装。代码如下：</p><p style="margin: 0pt; padding: 2pt 0px 0px 47pt; font-family: times new roman serif; font-size: 9pt"></p><p><span style="color:#646464;"><span style="font-size:18px;">@IocBean</span></span></p><p><span style="font-size:18px;"><span style="color:#646464;">@At</span>(<span style="color:#2A00FF;">&quot;/user&quot;</span>)</span></p><p><span style="font-size:18px;"><strong><span style="color:#7F0055;">public</span> <span style="color:#7F0055;">class</span></strong> UserAct {</span></p><p> <span style="color:#646464;"><span style="font-size:18px;">@Inject</span></span></p><p> <span style="font-size:18px;"><strong><span style="color:#7F0055;">protected</span></strong>Dao <span style="color:#0000C0;">dao</span>;</span></p><p> <span style="font-size:18px;"><span style="color:#3F7F5F;">//</span><span style="font-family:宋体;color:#3F7F5F;">查</span><span style="color:#3F7F5F;">--</span><span style="font-family:宋体;color:#3F7F5F;">登录</span></span></p><p> <span style="color:#646464;"><span style="font-size:18px;">@At</span></span></p><p> <span style="font-size:18px;"><span style="color:#646464;">@Ok</span>(<span style="color:#2A00FF;">&quot;json&quot;</span>)</span></p><p> <span style="font-size:18px;"><strong><span style="color:#7F0055;">public</span></strong>Object doLogin(<span style="color:#646464;">@Param</span>(<span style="color:#2A00FF;">&quot;uid&quot;</span>)String <span style="color:#6A3E3E;">uid</span>,<span style="color:#646464;">@Param</span>(<span style="color:#2A00FF;">&quot;pwd&quot;</span>)String <span style="color:#6A3E3E;">pwd</span>, HttpSession <span style="color:#6A3E3E;">session</span>,HttpServletRequest <span style="color:#6A3E3E;">req</span>){</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NutMap <span style="color:#6A3E3E;">re</span>= <strong><span style="color:#7F0055;">new</span></strong> NutMap();</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; User <span style="color:#6A3E3E;">user</span>= <span style="color:#0000C0;">dao</span>.fetch(User.<strong><span style="color:#7F0055;">class</span></strong>,<span style="color:#6A3E3E;">uid</span>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">if</span></strong>(<span style="color:#6A3E3E;">user</span> == <strong><span style="color:#7F0055;">null</span></strong>) {</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">re</span>.put(<span style="color:#2A00FF;">&quot;ok&quot;</span>, <strong><span style="color:#7F0055;">false</span></strong>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">re</span>.put(<span style="color:#2A00FF;">&quot;msg&quot;</span>, <span style="color:#2A00FF;">&quot;</span><span style="font-family:宋体;color:#2A00FF;">用户名不存在</span><span style="color:#2A00FF;">&quot;</span>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">return</span></strong><span style="color:#6A3E3E;">re</span>;</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">if</span></strong>(!<span style="color:#6A3E3E;">pwd</span>.equals(<span style="color:#6A3E3E;">user</span>.getPwd())){</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">re</span>.put(<span style="color:#2A00FF;">&quot;ok&quot;</span>, <strong><span style="color:#7F0055;">false</span></strong>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">re</span>.put(<span style="color:#2A00FF;">&quot;msg&quot;</span>, <span style="color:#2A00FF;">&quot;</span><span style="font-family:宋体;color:#2A00FF;">密码不正确</span><span style="color:#2A00FF;">&quot;</span>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">return</span></strong><span style="color:#6A3E3E;">re</span>;</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#3F7F5F;">//</span><span style="font-family:宋体;color:#3F7F5F;">登录成功后</span><span style="color:#3F7F5F;">...</span><span style="font-family:宋体;color:#3F7F5F;">将用户信息保存到</span><span style="color:#3F7F5F;">session</span></span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">session</span>.setAttribute(<span style="color:#2A00FF;">&quot;me&quot;</span>, <span style="color:#6A3E3E;">user</span>);</span></p><p><span style="font-size:18px;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">re</span>.put(<span style="color:#2A00FF;">&quot;ok&quot;</span>,<strong><span style="color:#7F0055;">true</span></strong>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">re</span>.put(<span style="color:#2A00FF;">&quot;msg&quot;</span>, <span style="color:#2A00FF;">&quot;user/goIndex&quot;</span>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">return</span></strong><span style="color:#6A3E3E;">re</span>;<span style="color:#3F7F5F;">//</span><span style="font-family:宋体;color:#3F7F5F;">对象</span></span></p><p><span style="font-size:18px;"> }</span></p><p><span style="font-size:18px;">&nbsp;</span></p><p> <span style="color:#646464;"><span style="font-size:18px;">@At</span></span></p><p> <span style="font-size:18px;"><span style="color:#646464;">@Ok</span>(<span style="color:#2A00FF;">&quot;beetl:web/admin.html&quot;</span>)<span style="color:#3F7F5F;">//</span><span style="font-family:宋体;color:#3F7F5F;">用户登录成功，跳转到后台管理页面</span></span></p><p> <span style="font-size:18px;"><strong><span style="color:#7F0055;">public</span><span style="color:#7F0055;">void</span></strong> goIndex(HttpSession <span style="color:#6A3E3E;">session</span>,HttpServletRequest <span style="color:#6A3E3E;">req</span>){</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; User <span style="color:#6A3E3E;">loginuser</span>=(User)<span style="color:#6A3E3E;">session</span>.getAttribute(<span style="color:#2A00FF;">&quot;me&quot;</span>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">req</span>.setAttribute(<span style="color:#2A00FF;">&quot;user&quot;</span>, <span style="color:#6A3E3E;">loginuser</span>);</span></p><p><span style="font-size:18px;"> }</span></p><p><span style="font-size:18px;">}</span></p><br />  </td>
        </tr>
        <tr>
          <td class="col0">3.5.9 匹配视图</td>
          <td class="col1"><p class="s5" style="margin: 0pt; padding: 9pt 0px 0px 5pt; text-indent: 21pt; font-family: 宋体; font-size: 18px; line-height: 28px;">通过注解<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">@Ok&nbsp;</span>和<span class="s6" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">@Fail&nbsp;</span>可以为入口函数声明不同的视图渲染方式。执行一个业务逻辑可 能有两种结果：</p><p class="s11" style="margin: 0pt; padding: 1pt 0px 0px 26pt; font-family: Wingdings; font-size: 9pt;">?&nbsp;<span class="s5" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 18px;">成功，正常返回。</span></p><p class="s11" style="margin: 0pt; padding: 1pt 0px 0px 26pt; font-family: Wingdings; font-size: 9pt;">?&nbsp;<span class="s5" style="margin: 0px; padding: 0px; font-family: 宋体; font-size: 18px;">失败，特指入口方法抛出异常。</span></p><p class="s6" style="margin: 0pt; padding: 1pt 0px 0px 26pt; font-family: " times="" new="" roman="" serif="" font-size:="" 18px=""></p><p><span style="font-size:18px;"><span style="font-family:'Segoe UI','sans-serif';color:#292B2C;background:white;">@Ok</span><span style="font-family:宋体;color:#292B2C;background:white;">和</span><span style="font-family:'Segoe UI','sans-serif';color:#292B2C;background:white;">@Fail</span><span style="font-family:宋体;color:#292B2C;background:white;">两个注解的值只能是一个字符串，它们的格式是：</span></span></p><p style="text-align:center;"><strong><span style="font-size:18px;"><span style="font-family:'Segoe UI','sans-serif';color:#292B2C;background:white;">&quot;</span><span style="font-family:宋体;color:red;background:white;">视图类型</span><span style="font-family:'Segoe UI','sans-serif';color:#292B2C;background:white;">:</span><span style="font-family:宋体;color:#292B2C;background:white;">视图值</span><span style="font-family:'Segoe UI','sans-serif';color:#292B2C;background:white;">&quot;</span></span></strong></p><p><span style="font-size:18px;"><span style="font-family:宋体;">视图的任务就是将入口函数的返回值（一个</span>Java<span style="font-family:宋体;">对象）渲染到</span> HTTP <span style="font-family:宋体;">响应流中。</span><span style="font-family:宋体;background:white;">那么怎么通过字符串，匹配到视图呢？</span></span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">现在</span> Nutz.Mvc<span style="font-family:宋体;">自带的主要视图类型有：</span></span></p><p><span style="font-size:18px;">1)<span style="font-family: Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>JSP <span style="font-family:宋体;">－</span> <span style="font-family:宋体;">采用</span> JSP <span style="font-family:宋体;">模板输出网页</span></span></p><p><span style="font-size:18px;">2)<span style="font-family: Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Redirect <span style="font-family:宋体;">－按照给定的视图值，发送</span> HTTP <span style="font-family:宋体;">重定向命令到客户端</span></span></p><p><span style="font-size:18px;">3)<span style="font-family: Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Forward <span style="font-family:宋体;">－</span> <span style="font-family:宋体;">服务器端中转，按照给定的视图值，服务器内部重定向到指定的地址</span></span></p><p><span style="font-size:18px;">4)<span style="font-family: Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Json <span style="font-family:宋体;">－</span> <span style="font-family:宋体;">将对象输出成</span> Json <span style="font-family:宋体;">字符串</span></span></p><p><span style="font-size:18px;">5)<span style="font-family: Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>void – <span style="font-family:宋体;">空白视图，对</span> HTTP <span style="font-family:宋体;">输出流不做任何处理，空实现</span></span></p><p><span style="font-size:18px;">6)<span style="font-family: Times New Roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Raw - <span style="font-family:宋体;">二进制输出，图片输出，文件下载等</span></span></p><p><span style="font-size:18px;">Nutz.Mvc<span style="font-family:宋体;">支持定制自己的视图规则，例如</span><span style="color:#2A00FF;">&quot;beetl:web/admin.html&quot;</span><span style="font-family:宋体;">，指定用模板引擎</span>Beetl<span style="font-family:宋体;">渲染</span>HTTP<span style="font-family:宋体;">输出流输出</span>WEB-INF/web<span style="font-family: 宋体;">目录下的</span>admin.html<span style="font-family: 宋体;">页面</span><span style="font-family:宋体;">。</span></span></p><span style="font-size:18px;"><span style="font-family: 宋体;">为了验证成功登录，在</span><span style="font-family: Times New Roman, serif;">WebRoot\WEB-INF\web</span><span style="font-family: 宋体;">目录下，新建一个</span><span style="font-family: Times New Roman, serif;">admin.html</span><span style="font-family: 宋体;">页面，作为输出的目标视图。</span><br /></span><br />  </td>
        </tr>
        <tr>
          <td class="col0">3.5.10 Beetl配置</td>
          <td class="col1"><p class="s5" style="margin: 0pt; padding: 9pt 0px 0px 26pt; font-family: 宋体; font-size: 18px;">在&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">conf&nbsp;</span>目录下创建&nbsp;<span class="s6" style="margin: 0px; padding: 0px; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="">beetl.properties</span>，添加一条配置项设置根路径，其他的采用默认值。</p><p style="margin: 0pt; padding: 3pt 0px 0px 47pt; font-family: times new roman serif; font-size: 9pt"><strong><span style="font-size:10.0pt;font-family:'Times New Roman','serif';color:red;">RESOURCE.root=/WEB-INF/</span></strong><br /><br /></p><p class="s6" style="margin: 0pt; padding: 0px 0px 0px 5pt; text-indent: 21pt; font-family: " times="" new="" roman="" serif="" font-size:="" 18px="" line-height:="" 28px="" text-align:="" justify="">Web&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">项目系统中，除系统首页以外，其他前端页面都可以使用&nbsp;</span>Beetl&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">模板引擎渲染，</span>Beetl&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">远超过主流&nbsp;</span>Java&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">模板引擎性能（引擎性能&nbsp;</span>5<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">～</span>6&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">倍与&nbsp;</span>freemaker<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">，</span>2&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">倍于&nbsp;</span>JSP<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">），而且消耗较低 的&nbsp;</span>CPU<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">。使用&nbsp;</span>Beetl&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">的目的是将模板文件和数据通过模板引擎快速生成最终的&nbsp;</span>HTML&nbsp;<span class="s5" style="margin: 0px; padding: 0px; text-indent: 0px; font-family: 宋体; font-size: 18px;">代码， 通过浏览器呈现出来。</span></p>  </td>
        </tr>
        <tr>
          <td class="col0">3.5.11 退出系统</td>
          <td class="col1"><p><span style="font-size:18px;"><span style="font-family:宋体;">为了验证退出系统功能，修改</span>admin.html<span style="font-family:宋体;">页面，在页面上添加一个</span>easyui<span style="font-family:宋体;">按钮，按钮的点击事件为请求登出系统。</span></span></p><p><span style="font-size:18px;">1. <span style="font-family:楷体_GB2312;">引用</span>js<span style="font-family:楷体_GB2312;">和</span>css</span></p><p><span style="font-size:18px;"><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">link</span> <span style="color:#7F007F;">rel</span>=<em><span style="color:#2A00FF;">&quot;stylesheet&quot;</span></em> <span style="color:#7F007F;">href</span>=<em><span style="color:#2A00FF;">&quot;${ctxPath}/include/easyui/themes/default/easyui.css&quot;</span></em><span style="color:teal;">&gt;</span></span></p><p><span style="font-size:18px;"><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">link</span> <span style="color:#7F007F;">rel</span>=<em><span style="color:#2A00FF;">&quot;stylesheet&quot;</span></em> <span style="color:#7F007F;">href</span>=<em><span style="color:#2A00FF;">&quot;${ctxPath}/include/easyui/themes/icon.css&quot;</span></em><span style="color:teal;">&gt;</span></span></p><p><span style="font-size:18px;"><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">script</span> <span style="color:#7F007F;">src</span>=<em><span style="color:#2A00FF;">&quot;${ctxPath}/include/js/jquery.min.js&quot;</span></em><span style="color:teal;">&gt;&lt;/</span><span style="color:#3F7F7F;">script</span><span style="color:teal;">&gt;</span></span></p><p><span style="font-size:18px;"><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">script</span> <span style="color:#7F007F;">src</span>=<em><span style="color:#2A00FF;">&quot;${ctxPath}/include/easyui/jquery.easyui.min.js&quot;</span></em><span style="color:teal;">&gt;&lt;/</span><span style="color:#3F7F7F;">script</span><span style="color:teal;">&gt;</span></span></p><p><span style="font-size:18px;"><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">script</span> <span style="color:#7F007F;">src</span>=<em><span style="color:#2A00FF;">&quot;${ctxPath}/include/easyui/locale/easyui-lang-zh_CN.js&quot;</span></em><span style="color:teal;">&gt;&lt;/</span><span style="color:#3F7F7F;">script</span><span style="color:teal;">&gt;</span></span></p><p><span style="font-size:18px;">2. <span style="font-family:楷体_GB2312;">添加按钮</span></span></p><p><span style="font-size:18px;"><span style="color:teal;">&lt;</span><span style="color:#3F7F7F;">a</span> <span style="color:#7F007F;">id</span>=<em><span style="color:#2A00FF;">&quot;logout&quot;</span></em> <span style="color:#7F007F;">href</span>=<em><span style="color:#2A00FF;">&quot;#&quot;</span></em> <span style="color:#7F007F;">class</span>=<em><span style="color:#2A00FF;">&quot;easyui-linkbutton&quot;</span></em> <span style="color:#7F007F;">data-options</span>=<em><span style="color:#2A00FF;">&quot;iconCls:'icon-cancel'&quot;</span></em><span style="color:teal;">&gt;</span><span style="font-family:宋体;">我要退出系统</span><span style="color:teal;">&lt;/</span><span style="color:#3F7F7F;">a</span><span style="color:teal;">&gt;</span></span></p><p><span style="font-size:18px;">3. <span style="font-family:楷体_GB2312;">添加按钮事件</span></span></p><p><span style="background:white;"><span style="font-size:18px;">$(<strong><span style="color:#7F0055;">function</span></strong>(){</span></span></p><p><span style="background:white;"><span style="font-size:18px;">$(<span style="color:#2A00FF;">&quot;#logout&quot;</span>).click(<strong><span style="color:#7F0055;">function</span></strong>(){</span></span></p><p><span style="background:white;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp; top.location.href=<span style="color:#2A00FF;">&quot;${ctxPath}/user/doLogout&quot;</span>;</span></span></p><p><span style="background:white;"><span style="font-size:18px;">});</span></span></p><p><span style="background:white;"><span style="font-size:18px;">});</span></span></p><p><span style="font-size:18px;">4. <span style="font-family:楷体_GB2312;">全局变量</span>ctxPath</span></p><p><span style="font-size:18px;">ctxPath<span style="font-family:宋体;">是</span>Beetl<span style="font-family:宋体;">中的默认变量，表示</span>ServletContext Path<span style="font-family:宋体;">。使用方法是，用默认占位符号</span><span style="color:red;">${ }</span><span style="font-family:宋体;">将变量括起来</span><span style="color:red;background:white;">${</span><span style="color:#2A00FF;background:white;">ctxPath</span><span style="color:red;background:white;">}</span><span style="font-family:宋体;">，代表当前项目在浏览器地址栏中显示的路径，如</span>http://localhost:8080/newsnutz <span style="font-family:宋体;">。</span></span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">在前端页面中请求</span>/user/doLogout<span style="font-family:宋体;">时，</span>UserAct<span style="font-family:宋体;">子模块中添加响应该请求的方法，退出系统前，必须使得</span>session<span style="font-family:宋体;">中保存的信息失效，然后</span>@Ok(&quot;&gt;&gt;:/&quot;)<span style="font-family:宋体;">跳转到系统首页。</span></span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#646464;">@At</span></span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#646464;">@Ok</span>(<span style="color:#2A00FF;">&quot;&gt;&gt;:/&quot;</span>)</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">public</span><span style="color:#7F0055;">void</span></strong> doLogout(HttpSession <span style="color:#6A3E3E;">session</span>) {</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">session</span>.invalidate();</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p></td>
        </tr>
        <tr>
          <td class="col0">3.5.12 密码加密</td>
          <td class="col1"><p><span style="font-size:18px;"><span style="font-family:宋体;">为了减少重复代码的编写，提高开发效率，往往需要进行代码复用，</span> <span style="font-family:宋体;">就是把一个功能写成一个方法，以便当再次需要相同功能的时候，可以直接使用，而不用重新编码实现。在</span>cn.lrw.newsnutz.utils<span style="font-family:宋体;">包中创建</span>BaseAct<span style="font-family:宋体;">类，在这个类中封装各种公用的方法。</span></span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">（</span>1<span style="font-family:宋体;">）字符串加密方法。调用</span>Shiro<span style="font-family:宋体;">中的</span>SHA<span style="font-family:宋体;">加密算法，可用于密码的不可逆加密。</span></span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">protected</span></strong> StringlrwCode(String <span style="color:#6A3E3E;">text</span>,String <span style="color:#6A3E3E;">salt</span>){</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">if</span></strong>(<span style="color:#6A3E3E;">salt</span>.equals(<span style="color:#2A00FF;">&quot;&quot;</span>))<span style="color:#6A3E3E;">salt</span>=<span style="color:#2A00FF;">&quot;abcdefghijklmnopqrstuvwx&quot;</span>;</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">return</span> <span style="color:#7F0055;">new</span></strong> Sha256Hash(<span style="color:#6A3E3E;">text</span>,<span style="color:#6A3E3E;">salt</span>,1024).toBase64();</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp; }</span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">（</span>2<span style="font-family:宋体;">）修改</span>UserAct<span style="font-family:宋体;">类，使其继承新建的</span>BaseAct<span style="font-family:宋体;">类</span></span></p><p><span style="font-size:18px;"><strong><span style="color:#7F0055;">public</span><span style="color:#7F0055;">class</span></strong> UserAct <strong><span style="color:#7F0055;">extends</span></strong> BaseAct {</span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">在</span>UserAct<span style="font-family:宋体;">的登录方法</span>doLogin<span style="font-family:宋体;">中调用此方法</span></span></p><p><span style="font-size:18px;">String <span style="color:#6A3E3E;">p</span>=lrwCode(<span style="color:#6A3E3E;">pwd</span>,<span style="color:#2A00FF;">&quot;&quot;</span>);</span></p><p><span style="font-size:18px;"><strong><span style="color:#7F0055;">if</span></strong> (!<span style="color:#6A3E3E;">p</span>.equals(<span style="color:#6A3E3E;">user</span>.getPwd())) {</span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">（</span>3<span style="font-family:宋体;">）修改</span>MainSetup<span style="font-family:宋体;">中的初始化密码</span></span></p><p><span style="font-size:18px;">String <span style="color:#6A3E3E;">salt</span>=<span style="color:#2A00FF;">&quot;abcdefghijklmnopqrstuvwx&quot;</span>;</span></p><p><span style="font-size:18px;"><span style="color:#6A3E3E;">user</span>.setPwd(<strong><span style="color:#7F0055;">new</span></strong> Sha256Hash(<span style="color:#2A00FF;">&quot;123&quot;</span>,<span style="color:#6A3E3E;">salt</span>, 1024).toBase64());</span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">（</span>4<span style="font-family:宋体;">）删除数据库</span>user<span style="font-family:宋体;">表中记录</span></span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">（</span>5<span style="font-family:宋体;">）重新运行项目，将加密的数据写入数据库，测试登录跳转功能。</span></span></p></td>
        </tr>
        <tr>
          <td class="col0">3.5.13 登录Filter</td>
          <td class="col1"><p><span style="font-size:18px;"><span style="font-family:宋体;">为了防止用户不登录系统就能够查看或改动系统中的敏感数据，往往在用户请求某种操作（登录、注册除外）前，系统自动检查用户是否已经登录，如果没有登录则返回登录页面。为了给用户一个比较明确的提示信息，我们可以在</span>WebRoot\error<span style="font-family:宋体;">目录下，新建一个</span>nologin.html<span style="font-family:宋体;">页面，页面提示登录失效，</span>2<span style="font-family:宋体;">秒钟后跳转到登录页面（系统首页）。</span></span></p><p><span style="font-size:18px;"><strong>nologin.html</strong><span style="font-family:宋体;">页面</span>Body<span style="font-family:宋体;">中的内容如下，主要用于提示是否有效登录，当然可以设计实现很漂亮的提示页面风格和提示信息。</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&lt;<strong>h1</strong>&gt;</span><span style="font-family:宋体;color:#444444;">登录失效</span><span style="color:#444444;">&lt;/<strong>h1</strong>&gt;</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&lt;<strong>p</strong>&gt;</span><span style="font-family:宋体;color:#444444;">对不起，您没有登录或者登录已超时。</span><span style="color:#444444;">&lt;/<strong>p</strong>&gt;</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&lt;<strong>script</strong> type=</span><span style="color:#880000;">&quot;text/javascript&quot;</span><span style="color:#444444;">&gt;</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp; setTimeout(reDo,</span><span style="color:#880000;">2000</span><span style="color:#444444;">);</span></span></p><p><span style="font-size:18px;"><span style="color:#444444;">&nbsp;&nbsp;&nbsp;&nbsp; <strong>function</strong></span><strong><span style="color:#880000;">reDo</span></strong><span style="color:#444444;">(){ top.location.href = </span><span style="color:#880000;">&quot;../&quot;</span><span style="color:#444444;">;}</span></span></p><p><span style="color:#444444;"><span style="font-size:18px;">&lt;/<strong>script</strong>&gt;</span></span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">在</span>cn.lrw.newsnutz.utils<span style="font-family:宋体;">包中创建</span>LoginFilter<span style="font-family:宋体;">类实现接口</span>ActionFilter<span style="font-family:宋体;">，检查用户是否登录（检查当前</span>Session<span style="font-family:宋体;">是否带有</span>me<span style="font-family:宋体;">这个</span>Attribute<span style="font-family:宋体;">），从而确定是否允许执行请求的某种操作。</span></span></p><p><span style="font-size:18px;"><strong><span style="color:#7F0055;">public</span> <span style="color:#7F0055;">class</span></strong>LoginFilter <strong><span style="color:#7F0055;">implements</span></strong> ActionFilter {</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#646464;">@Override</span></span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">public</span></strong> View match(ActionContext<span style="color:#6A3E3E;">context</span>) {</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpServletRequest <span style="color:#6A3E3E;">request</span>= <span style="color:#6A3E3E;">context</span>.getRequest();</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; User <span style="color:#6A3E3E;">user</span> = (User) <span style="color:#6A3E3E;">request</span>.getSession().getAttribute(<span style="color:#2A00FF;">&quot;me&quot;</span>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String <span style="color:#6A3E3E;">contentType</span>= <span style="color:#6A3E3E;">request</span>.getContentType();</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">if</span></strong> (<span style="color:#6A3E3E;">user</span> == <strong><span style="color:#7F0055;">null</span></strong>){</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">if</span></strong>(Strings.<em>sNull</em>(<span style="color:#6A3E3E;">contentType</span>).contains(<span style="color:#2A00FF;">&quot;application/x-www-form-urlencoded&quot;</span>)) </span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">context</span>.getResponse().setHeader(<span style="color:#2A00FF;">&quot;sessionstatus&quot;</span>, <span style="color:#2A00FF;">&quot;timeout&quot;</span>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServerRedirectView <span style="color:#6A3E3E;">view</span>= <strong><span style="color:#7F0055;">new</span></strong> ServerRedirectView(<span style="color:#2A00FF;">&quot;/error/nologin.html&quot;</span>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">return</span></strong><span style="color:#6A3E3E;">view</span>;</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#6A3E3E;">request</span>.setAttribute(<span style="color:#2A00FF;">&quot;me&quot;</span>, <span style="color:#6A3E3E;">user</span>);</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="color:#7F0055;">return</span> <span style="color:#7F0055;">null</span></strong>;</span></p><p><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp; }</span></p><p><span style="font-size:18px;">}</span></p><p><span style="font-size:18px;">&nbsp;</span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">接下来，稍微修改一下</span>UserAct<span style="font-family:宋体;">类，其中用到</span>@Filters<span style="font-family:宋体;">注解。</span></span></p><p><span style="font-size:18px;"><span style="font-family:Wingdings;">l<span style="font-family: Times New Roman;">&nbsp; </span></span>@Filters({@By(type=LoginFilter.class)})<span style="font-family:宋体;">，请求执行</span>UserAct<span style="font-family:宋体;">类中的方法，必须先通过</span>Filter<span style="font-family:宋体;">中的检验。</span></span></p><p><span style="font-size:18px;"><span style="color:#646464;">@Filters</span>({<span style="color:#646464;">@By</span>(type=LoginFilter.<strong><span style="color:#7F0055;">class</span></strong>)})</span></p><p><span style="font-size:18px;"><strong><span style="color:#7F0055;">public</span> <span style="color:#7F0055;">class</span></strong>UserAct <strong><span style="color:#7F0055;">extends</span></strong> BaseAct{</span></p><p><span style="font-size:18px;"><span style="font-family:Wingdings;">l<span style="font-family: Times New Roman;">&nbsp; </span></span>@Filters()<span style="font-family:宋体;">，用户登录肯定无法通过</span>Filter<span style="font-family:宋体;">检验，所以在</span>doLogin<span style="font-family:宋体;">方法前添加一个无参数的</span>@Filters()<span style="font-family:宋体;">，表示临时屏蔽</span>Filter<span style="font-family:宋体;">检验，允许没有登录的用户请求执行</span>doLogin<span style="font-family:宋体;">方法。</span></span></p><p><span style="font-size:18px;"><span style="color:#646464;">@Filters</span>()</span></p><p><span style="font-size:18px;"><strong><span style="color:#7F0055;">public</span></strong> Object doLogin(</span></p><p><span style="font-size:18px;"><span style="font-family:宋体;">重新运行项目，查看是否能正常登录跳转；查看是否在退出后，在浏览器地址栏输入：</span><a href="http://localhost:8080/newsnutz/user/goIndex">http://localhost:8080/newsnutz/user/goIndex</a><span style="font-family:宋体;">，回车，能否直接访问后台管理页面</span>admin.html<span style="font-family:宋体;">，这个页面应该是用户登录后才能访问的。如果你的</span>Filter<span style="font-family:宋体;">使用正确，由于没有权限直接访问</span>admin.html<span style="font-family:宋体;">，会自动跳转到</span>error/nologin.html<span style="font-family:宋体;">页面。</span></span></p></td>
        </tr>

		</tbody>
    </table>
<div th:include="include :: footer"></div>
</body>
</html>
